#!/bin/bash

export BASE_DATA_PATH=/home/mixagol/data
export CUR_DATA_DIR=${BASE_DATA_PATH}/3_raw_matrix_nw/simulation/pupy
export LC_ALL=C

g++ -O3 -std=c++0x -c 3_raw_matrix_nw/simulation/nw_sim_process.cpp -fPIC -lstdc++ -o 3_raw_matrix_nw/simulation/nw_sim_process.o
g++ -O3 -std=c++0x -shared -o 3_raw_matrix_nw/simulation/nw_sim_process.so 3_raw_matrix_nw/simulation/nw_sim_process.o
rm 3_raw_matrix_nw/simulation/nw_sim_process.o

mkdir -p $CUR_DATA_DIR/input_files
3_raw_matrix_nw/simulation/create_input_pupy.py | split -a5 -l 1 - $CUR_DATA_DIR/input_files/

mkdir -p $CUR_DATA_DIR/output_files

export SYNC_DIR=/home/mixagol/work/data/nw_sim/sync
export INPUT_DIR=/home/mixagol/work/data/nw_sim/input
export OUTPUT_DIR=/home/mixagol/work/data/nw_sim/output

mkdir -p $INPUT_DIR
mkdir -p $OUTPUT_DIR
mkdir -p $SYNC_DIR

find $CUR_DATA_DIR/input_files -type f | xargs -n1 -I {} cp {} $INPUT_DIR

# на victoria
mpirun -q quad -np 20 ~/runner /home/mixagol/trunk/gene-class/3_raw_matrix_nw/simulation/run_worker.sh $SYNC_DIR $INPUT_DIR $OUTPUT_DIR

mv $OUTPUT_DIR ${CUR_DATA_DIR}/output

zcat ${CUR_DATA_DIR}/output/* | gzip > ${CUR_DATA_DIR}/output.txt.gz

pv ${CUR_DATA_DIR}/output.txt.gz | zcat | 3_raw_matrix_nw/simulation/interpolate.py > ${CUR_DATA_DIR}/interpolation.txt
pv ${CUR_DATA_DIR}/interpolation.txt | tools/create_bsddb.py ${CUR_DATA_DIR}/evsd.db



